package com.zhang.homework.reflection1;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Executable;
import java.lang.reflect.Method;

/**
 * @author zhang
 * @time 2022/02/16 20:26:54
 */
@Target({ElementType.TYPE,ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@interface MyAnnotation {
    String value() default "abc";
}
@MyAnnotation("star-product")
interface I {
    @MyAnnotation("products/test")
    void f1(int x);
}
class A implements I {

    @Override
    public void f1(int x) {
        StackTraceElement[] stackTrace = new RuntimeException().getStackTrace();
        String methodName = stackTrace[0].getMethodName();
        Class clz = this.getClass().getInterfaces()[0];
        MyAnnotation a= (MyAnnotation) clz.getAnnotation(MyAnnotation.class);
        try {

            
            Executable m = clz.getMethod(methodName);
            System.out.println(m.getParameters());
            m.getParameters();

            a = m.getAnnotation(MyAnnotation.class);
            System.out.println(a.value());
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        }
    }
}

public class Test {
    public static void main(String[] args) {
        I i = new A();
        i.f1(1);

    }



}
